package com.caine.proxy.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtil implements ApplicationContextAware {

    private static ApplicationContext staticContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        staticContext = applicationContext;
    }

    public static Object getBeanByClass(Class<?> clazz){
        return staticContext.getBean(clazz);
    }

    public static Object getBeanByName(String cName){
        return staticContext.getBean(cName);
    }

    public static ApplicationContext getContext(){
        return staticContext;
    }
}
